#include<bits/stdc++.h>
using namespace std;
int main(){
	//freopen("sequence.in" , "r" , stdin);
	//freopen("sequence.out" , "w" , stdout);
	int k , n , p = 1 , ans = 0;
	cin >> k >> n;
	while(n){
		int m;
		m = n % 2;
		n = n / 2;
		if(m == 1){
			m = m * p;
			ans = ans + m;
		}
		p = p * k;
	}
	cout << ans << endl;
	return 0;
}
